/**
 * 管理初始化
 */
var Projectinfo = {
    id: "ProjectinfoTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Projectinfo.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
            {title: '项目名称', field: 'projectname', visible: true, align: 'center', valign: 'middle'},
            {title: '项目地址', field: 'address', visible: true, align: 'center', valign: 'middle'},
            {title: '项目详细地址', field: 'addressdetail', visible: true, align: 'center', valign: 'middle'},
            {title: '项目联系人', field: 'contacter', visible: true, align: 'center', valign: 'middle'},
            {title: '项目联系电话', field: 'phone', visible: true, align: 'center', valign: 'middle'},
            {title: '项目建设单位', field: 'conunit', visible: true, align: 'center', valign: 'middle'},
            {title: '项目总包单位', field: 'totaluinit', visible: true, align: 'center', valign: 'middle'},
            {title: '项目概况', field: 'overview', visible: true, align: 'center', valign: 'middle'},
            {title: '项目工程量', field: 'quantity', visible: true, align: 'center', valign: 'middle'},
            {title: '项目附件', field: 'isannex',formatter: function (value, row, index) {
                    if (value == "1"){
                        return "有";
                    } else {
                        return "没有";
                    }}, visible: true, align: 'center', valign: 'middle'},
            {title: '项目备注', field: 'projectremark', visible: true, align: 'center', valign: 'middle'},
            {title: '提交人电话', field: 'submitterphone', visible: true, align: 'center', valign: 'middle'},
            {title: '银行卡号', field: 'bankcode', visible: true, align: 'center', valign: 'middle'},
            {title: '开户行', field: 'bankname', visible: true, align: 'center', valign: 'middle'},
            {title: '持卡人姓名', field: 'cardholder', visible: true, align: 'center', valign: 'middle'},
            {title: '支付宝', field: 'alipay', visible: true, align: 'center', valign: 'middle'},
            {title: '支付宝姓名', field: 'alipayname', visible: true, align: 'center', valign: 'middle'},
            {title: '微信', field: 'wechat', visible: true, align: 'center', valign: 'middle'},
            {title: '提交时间', field: 'subtime', visible: true, align: 'center', valign: 'middle'},
            {title: '审核时间', field: 'audittime', visible: true, align: 'center', valign: 'middle'},
            {title: '备注', field: 'remark', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
Projectinfo.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        Projectinfo.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加
 */
Projectinfo.openAddProjectinfo = function () {
    var index = layer.open({
        type: 2,
        title: '添加',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/projectinfo/projectinfo_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看详情
 */
Projectinfo.openProjectinfoDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '详情',
            area: ['830px', '660px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/projectinfo/projectinfo_detail/' + Projectinfo.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除
 */
Projectinfo.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/projectinfo/delete", function (data) {
            Feng.success("删除成功!");
            Projectinfo.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("projectinfoId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询列表
 */
Projectinfo.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    queryData['starttime'] = $("#starttime").val();
    queryData['endtime'] = $("#endtime").val();
    Projectinfo.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = Projectinfo.initColumn();
    var table = new BSTable(Projectinfo.id, "/projectinfo/nopasslistinfo", defaultColunms);
    table.setPaginationType("client");
    Projectinfo.table = table.init();
});
